/*
 * Copyright (c) 2016 The ZLToolKit project authors. All Rights Reserved.
 *
 * This file is part of ZLToolKit(https://github.com/ZLMediaKit/ZLToolKit).
 *
 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
 */

#include <csignal>
#include <iostream>
#include "Util/logger.h"
#include "Network/TcpClient.h"
#include "Util/SqlPool.h"

#include "test_CtcpClient2.h"
using namespace std;
using namespace toolkit;

int main() {
    // 设置日志系统
    Logger::Instance().add(std::make_shared<ConsoleChannel>());
    Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());

    vector<TestClient::Ptr> vec_client;
    int num = 1;
    while (num--)
    {
        TestClient::Ptr client(new TestClient());//必须使用智能指针
		client->startConnect("192.168.9.194", 10000);//连接服务器
		vec_client.push_back(client);
    }

	////定时发送数据到服务器
	//auto buf = BufferRaw::create();
 //   if (buf) {
 //      // buf->assign("[BufferRaw]\0");
 //       buf->setCapacity(1024*1024*4);
 //       buf->setSize(1024 * 1024 * 4);
 //       memset(buf->data(), 'A', buf->size());
 //   }

 //   while (true)
 //   {
	//	for (std::vector<TestClient::Ptr>::iterator it = vec_client.begin(); it != vec_client.end(); it++) {
 //           if ((*it)->isConnect)
 //           {
	//			cout << *it << ",";
	//			(*it)->send(buf);
 //           }
 //           //usleep(20);
	//	}
 //   }


    //TcpClientWithSSL<TestClient>::Ptr clientSSL(new TcpClientWithSSL<TestClient>());//必须使用智能指针
    //clientSSL->startConnect("127.0.0.1",9001);//连接服务器

    //退出程序事件处理
    static semaphore sem;
    signal(SIGINT, [](int) { sem.post(); });// 设置退出信号
    sem.wait();
    return 0;
}